package com.hzbank.generate.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("ds")
public class MyDataSourceController {
    @Autowired
    private DataSource dataSource;
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @RequestMapping("druid")
    public Map<String,Object> dataSource() throws SQLException {
        Map map = new HashMap();
//        map.put("默认数据源为：",dataSource.getClass());
//        map.put("数据库连接实例：",dataSource.getConnection());
        map.put("默认数据源为：",dataSource.getClass());
        map.put("数据库连接实例：","aa");
        map.put("druid数据监控登录页：","localhost:8080/druid");
        map.put("账户名/密码","admin/123456");
        System.out.println("默认数据源为：" + dataSource.getClass());
        System.out.println("数据库连接实例：" + dataSource.getConnection());
        System.out.println("druid数据监控登录页：localhost:8080/druid");
        System.out.println("账户名/密码：admin/123456");
        //访问数据库
        Integer n = jdbcTemplate.queryForObject("SELECT count(*) from `account_info`", Integer.class);
        System.out.println("user 表中共有" + n + "条数据。");
        String a = "s";

        return map;

    }

}
